<template>
 <div>
<el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
>
  <el-form ref="form" :model="form" label-width="80px" :rules="rules">
    <el-form-item label="学科名称" prop="subjectName">
    <el-input v-model="form.subjectName" placeholder="请输入内容" ></el-input>
  </el-form-item>
  <el-form-item label="是否显示">
   <el-switch
  v-model="form.isFrontDisplay"
  active-color="#13ce66"
  inactive-color="#ff4949"
  :active-value="false"
   :inactive-value="true">
 </el-switch>
  </el-form-item>
</el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="closeDialog">取 消</el-button>
    <el-button type="primary" @click="changeSubject">确 定</el-button>
  </span>
</el-dialog>
 </div>
</template>

<script>
import { detail } from '@/api/hmmm/subjects.js'
export default {

  name: 'subjectAdd',
  props: {
  },
  data () {
    return {
      dialogVisible: false,
      form: {
        id: null,
        isFrontDisplay: true,
        subjectName: ''
      },
      rules: {
        subjectName: [{ required: true, message: '请选择', trigger: 'blur' }]
      }
    }
  },
  methods: {
    async openDialog () {
      this.dialogVisible = true
    },
    closeDialog () {
      this.form = {
        id: null,
        isFrontDisplay: true,
        subjectName: ''
      }
      this.$refs.form.resetFields()
      this.dialogVisible = false
    },
    async  changeSubject () {
      try {
        await this.$refs.form.validate()
        this.$emit('changenSubject', this.form)
      } catch (error) {
        console.log(error)
      }
    },
    async geteditList (id) {
      const { data } = await detail({ id })
      this.form = data
      this.openDialog()
    }
  }
}
</script>

<style scoped lang='less'>

</style>
